﻿#ifndef USERSETTINGS_H
#define USERSETTINGS_H
#include "globalinstance.h"
#include <QMutex>
#include <QVariant>

class UserSettings : public GlobalInstance<UserSettings>
{
    friend class GlobalInstance<UserSettings>;
    UserSettings();
public:
    void get_personal_setting();
    void save_personal_setting();
    void get_system_setting();
    void save_system_setting();
    void initSystemSettingFileName();
    void resetPersonalSetting(const QString& uid);
    bool getBool(const QString& key);
    int getInt(const QString& key);
    QString getString(const QString& key);
    QStringList getStringList(const QString& key);
    QVariant getValue(const QString& key);
    void setValue(const QString& key, const QVariant& value);
    bool setValueIfChanged(const QString& key, const QVariant& value);

    QStringList getIDs();
    QByteArray getHashedPW(const QString& id);
    void setPW(const QString& id, const QString& pw = QString());
    void setPW(const QString& id, const QByteArray& hashedPW);
    void clearIDPW(const QString& id = QString());

    static const QString sys_auto_login;
    static const QString sys_last_login_id;
    static const QString sys_save_password;
    static const QString sys_mic_index;
    static const QString sys_speaker_index;
    static const QString sys_video_index;
    static const QString sys_micphone_volume;
    static const QString sys_micphone_mute;
    static const QString sys_speaker_volume;
    static const QString sys_speaker_mute;
    static const QString sys_check_update_last;
    static const QString sys_server_domain;
    static const QString sys_server_proxy;
    static const QString sys_uuid;
    static const QString sys_idpw_section;
    static const QString sys_debug_file;
private:
    QMutex mutex_;
    QString personal_setting_fileName_;
    const QStringList personal_setting_typelist_;
    QString system_setting_fileName_;
    const QStringList system_setting_typelist_;
    QMap<QString,QVariant> setting_map;
};

#endif // USERSETTINGS_H
